package com.bitdf.txing.seckill.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Lizhiwei
 * @date 2023/8/25 21:26:35
 * 注释：
 */
@Configuration
public class MyMqConfig {
    /**
     * 秒杀交换机
     * @return
     */
    @Bean
    public Exchange seckiilExchange() {
        /*
         *   String name,
         *   boolean durable,
         *   boolean autoDelete,
         *   Map<String, Object> arguments
         * */
        return new TopicExchange("seckill-exchange", true, false);

    }

    /**
     * 秒杀完放进此队列 待订单服务生成订单
     * @return
     */
    @Bean("seckill.and.order.queue")
    public Queue orderSecKillOrrderQueue() {
        Queue queue = new Queue("seckill.and.order.queue", true, false, false);
        return queue;
    }

    /**
     * 秒杀交换机 === 秒杀后队列
     * @return
     */
    @Bean
    public Binding seckillAndOrderQueueBinding() {
        //String destination, DestinationType destinationType, String exchange, String routingKey,
        // 			Map<String, Object> arguments
        Binding binding = new Binding(
                "seckill.and.order.queue",
                Binding.DestinationType.QUEUE,
                "seckill-exchange",
                "seckill.and.order",
                null);
        return binding;
    }

    /**
     * 秒杀请求排队队列
     * @return
     */
    @Bean
    public Queue waitExecSeckillQueue() {
        Queue queue = new Queue("wait.exec.seckill.queue", true, false, false);
        return queue;
    }

    /**
     * 等待执行秒杀队列 === 秒杀交换机
     * @return
     */
    @Bean
    public Binding waitSeckillBinding() {
        //String destination, DestinationType destinationType, String exchange, String routingKey,
        // 			Map<String, Object> arguments
        Binding binding = new Binding(
                "wait.exec.seckill.queue",
                Binding.DestinationType.QUEUE,
                "seckill-exchange",
                "wait.exec.seckill",
                null);
        return binding;
    }





}
